# -*- coding: UTF-8 -*-
"""
@author: tgy
@file: demo04.py
@time: 2021/04/30
"""
from collections import namedtuple


def test01():
    ...
    name = 'zhangsan'
    name_iter = iter(name)
    # print(next(name_iter))
    while True:
        try:
            ...
            print(next(name_iter))
        except StopIteration as e:
            break
    nums = [0] * 5
    print(nums)


def test02():
    ...
    # 调用的是 list 的__str__
    print(str([1, 2, 3]))
    nums = [1, 2, 3, 4]
    # nums[1:2] = []
    del nums[1:2]
    print(nums)
    nums.append(5)
    print(nums.pop(0))
    print(nums)


class Stack:

    def __init__(self):
        self.stack = []

    def push(self, val):
        self.stack.append(val)

    def pop(self):
        if self.isEmpty():
            raise Exception('stack is empty')
        return self.stack.pop()

    def peek(self):
        if self.isEmpty():
            raise Exception('stack is empty')
        return self.stack[len(self.stack) - 1]

    def isEmpty(self):
        return len(self.stack) == 0


def test03():
    stack = Stack()
    stack.push(1)
    stack.push(2)
    stack.push(3)

    while not stack.isEmpty():
        ...
        print(stack.pop())


def test04():
    ...
    nums = [1, 2, 3]
    nums.extend('1111')
    print(nums)


def my_list(it):
    ...
    arr = []
    ite = iter(it)
    while True:
        try:
            arr.append(next(ite))
        except StopIteration as e:
            ...
            break
    return arr


def test05():
    ...
    student = namedtuple('Student', ('name', 'age'))
    student.name = 'zhangsan'
    student.age = 21
    print(student.name)
    print(dict(opt=123))
    print(my_list(range(10)))

def test06():
    ...
    print('张三'.encode('utf8'))
    print(b'\xe5\xbc\xa0\xe4\xb8\x89'.decode('utf8'))
    print(str(b'\xe5\xbc\xa0\xe4\xb8\x89', 'utf8'))

def test07():
    ...
    a = 1
    b = 2
    c = 3
    print(a < b < c)
    print(a != b < c)
    print(int('122121', base=4))

def test08():
    ...
    name = 'zhangsan'
    # [a,b)
    print(name[::-1])
    print(name[5:1:-1])
    print(chr(ord('5') + 1))
    print('name:{0}, age:{1}'.format('zhangsan', 21))
    print(bin(12))

if __name__ == '__main__':
    pass
    # test04()
    # test05()
    # age = 20
    # print(dir())
    # print(locals())
    test08()